// src/components/countdown/index.js
import $CountDown from '../../utils/countdown.js'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    endTime: {
      type: Number,
      value: 0
    },
    confirmTime: {
      type: Number,
      value:0
    },
    status: {
      type: String,
      
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    days: 0,
    hours:0,
    min: 0,
    sec: 0,
    status: String,
    delay:false
  },
  attached: function() {
    const self = this;
    if (this.properties.status == 'pay') {
      new $CountDown({
        date: new Date(this.properties.endTime),
        render(date) {
          const min = this.leadingZeros(date.min, 2) 
          const sec = this.leadingZeros(date.sec, 2)
          if (min == 0 && sec == 0) {
            self.setData({
              delay:true
            })
          } else {
            self.setData({
              delay: false,
              min: min,
              sec:sec
            })
          }
          
        }
      })
    } else if (this.properties.status == 'confirm') {
      new $CountDown({
        date: new Date(this.properties.confirmTime),
        render(date) {
          const days = this.leadingZeros(date.days, 1)
          const hours = this.leadingZeros(date.hours, 2)
          const min = this.leadingZeros(date.min, 2)  
          self.setData({
            days: days,
            hours:hours,
            min: min,
          })
        }
      })
    }
    
  },

  /**
   * 组件的方法列表
   */
  methods: {}
})
